####read in model utilities and targeted moments, and initialize model primitives
package = Readin_utilities(dir)
package_moments = Readin_moments(dir)

h_grid = collect(0.01:0.01:4.0)
kid_marr_hs = package[5]
kid_marr_coll = package[8]


nh = length(h_grid)

marrprobs = zeros(nh, 12)

state_indices = [5, 15, 24, 32, 43, 44] #CA, IA, MS, NY, TX, UT
ns = length(state_indices)

for i = 1:nh
    h = h_grid[i]

    for s = 1:ns
        l = state_indices[s]
        prob_marr_hs = 𝚽(kid_marr_hs[l, 2] + h*kid_marr_hs[l, 3] +  h^2*kid_marr_hs[l, 4] +  h^3*kid_marr_hs[l, 5])
        if h>3
            prob_marr_hs = kid_marr_hs[l, 6]
        end

        prob_marr_coll = 𝚽(kid_marr_coll[l, 2] + h*kid_marr_coll[l, 3] +  h^2*kid_marr_coll[l, 4] +  h^3*kid_marr_coll[l, 5])
        if h>3
            prob_marr_coll = kid_marr_coll[l, 6]
        end

        marrprobs[i, 2*(s - 1) + 1] =prob_marr_hs
        marrprobs[i, 2*(s - 1) + 2] =prob_marr_coll
    end
end

output = hcat(h_grid, marrprobs)
CSV.write("$dir\\Simulated_data\\marriage_probs.csv", DataFrame(output, :auto), header=false) #write CSV file

####
